/*!
 * \file test_framework.c
 *
 * All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.\n
 *
 * \version 3.0
 * \author jikw
 * \date 2016/04/12
 *
 */

#include <stdio.h>
#include <assert.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>

#include "apmtest_cunit.h"
#include "frcomm.h"
#include "frmem.h"
#include "frreport_comm.h"

//#include "t_frct_expect/t_frct_expect.h"
//#include "t_frstat_conn/t_frstat_conn.h"
//#include "t_frstat_port/t_frstat_port.h"
//#include "t_frstat_ct_conn/t_frstat_ct_conn.h"
#include "t_frreport_mng/t_frreport_mng.h"
#include "t_frreport_session_mng/t_frreport_session_mng.h"
#include "t_frame_params/t_frame_params.h"
#include "t_frct_hash/t_frct_hash.h"
#include "t_frproto_mng/t_frproto_mng.h"
#include "t_frstat_module/t_frstat_module.h"
#include "t_frstat_thread/t_frstat_thread.h"
#include "t_frssl_config/t_frssl_config.h"

int g_i_flag_run =1;
int g_i_task_chk_timer=FR_NO; /* 用于判断 g_thread_id_do_timer 线程是否在运行*/
void *g_p_memstat=NULL;

void add_suites(FunType *p_func, int i_suites_len, FunType fp)
{
    int i_loop = 0;
    for (;i_loop < i_suites_len; i_loop++)
    {
        if (p_func[i_loop] == NULL)
        {
            p_func[i_loop] = fp;
            break;
        }
    }
}

int main(int argc, char **argv)
{
    if (fr_slab_init(FR_MEM_BUFF_SIZE, "framework") == FR_FAIL)
        return FR_FAIL;

    apmtest_cunit_registry();

    FunType fun_suites[1024];
    memset(fun_suites, 0x00, sizeof(fun_suites));
    int i_suites_len = sizeof(fun_suites) / sizeof(FunType);
    int i_loop = 0;

    // 加载各个测试组件
    //t_frct_expect
//    add_suites(fun_suites, i_suites_len, add_suite__frexpect_node_free);
//    add_suites(fun_suites, i_suites_len, add_suite__list_node_show);
//    add_suites(fun_suites, i_suites_len, add_suite_frexpect_get);
//    add_suites(fun_suites, i_suites_len, add_suite_frexpect_output);
//    //t_frstat_conn
//    add_suites(fun_suites, i_suites_len, add_suite__conn_key);
//    add_suites(fun_suites, i_suites_len, add_suite__frstat_conns_add_conn);
//    add_suites(fun_suites, i_suites_len, add_suite__frstat_conns_add_refued_reset);
//    add_suites(fun_suites, i_suites_len, add_suite__frstat_conns_del);
//    add_suites(fun_suites, i_suites_len, add_suite_frstat_conns_add_conn_ct);
    //t_frstat_port
//    add_suites(fun_suites, i_suites_len, add_suite__conn_key2);
//    add_suites(fun_suites, i_suites_len, add_suite_frstat_ports_add_stat);
    //t_frstat_ct_conn
//    add_suites(fun_suites, i_suites_len, add_suite__frl7_conns_count);
//    add_suites(fun_suites, i_suites_len, add_suite__l7_node_free);
//    add_suites(fun_suites, i_suites_len, add_suite_frstat_ct_conns_add);
//    add_suites(fun_suites, i_suites_len, add_suite_frstat_ct_conns_destroy);
//    add_suites(fun_suites, i_suites_len, add_suite_frstat_ct_conns_init);
//    add_suites(fun_suites, i_suites_len, add_suite_frstat_ct_l7_conns_count);
//    add_suites(fun_suites, i_suites_len, add_suite_frstat_ct_l7_conns_del);

    //t_frreport_mng
    add_suites(fun_suites, i_suites_len, add_suite___frreport_get_ip);
    add_suites(fun_suites, i_suites_len, add_suite_frreport_mng_init);

    //t_frreport_session_mng
    add_suites(fun_suites, i_suites_len, add_suite_frreport_session_mng_clean);
    add_suites(fun_suites, i_suites_len, add_suite_frreport_session_mng_init);

    //t_frame_params
    add_suites(fun_suites, i_suites_len, add_suite_frame_params_get);

    //t_frct_hash
    add_suites(fun_suites, i_suites_len, add_suite___hash_node_show);
    add_suites(fun_suites, i_suites_len, add_suite_frct_hash_add);
    add_suites(fun_suites, i_suites_len, add_suite_frct_hash_del);
    add_suites(fun_suites, i_suites_len, add_suite_frct_hash_get);
    add_suites(fun_suites, i_suites_len, add_suite_frct_hash_init);
    add_suites(fun_suites, i_suites_len, add_suite_frct_hash_key);
    add_suites(fun_suites, i_suites_len, add_suite_frct_hash_output);

    //t_frproto_mng
    add_suites(fun_suites, i_suites_len, add_suite___frproto_add_list);
    add_suites(fun_suites, i_suites_len, add_suite___frproto_add_one);
    add_suites(fun_suites, i_suites_len, add_suite___frproto_cfg_get_param);
    add_suites(fun_suites, i_suites_len, add_suite___frproto_define_change_status);
    add_suites(fun_suites, i_suites_len, add_suite___frproto_hash_get);
    add_suites(fun_suites, i_suites_len, add_suite___frproto_is_same);
    add_suites(fun_suites, i_suites_len, add_suite___frproto_mng_key);
    add_suites(fun_suites, i_suites_len, add_suite___frproto_pri_add);
    add_suites(fun_suites, i_suites_len, add_suite___hash_node_mng_find);
    add_suites(fun_suites, i_suites_len, add_suite___hash_node_mng_find_complete);
    add_suites(fun_suites, i_suites_len, add_suite___hash_node_mng_show);
    add_suites(fun_suites, i_suites_len, add_suite___hash_node_proto_port_range_exist);
    add_suites(fun_suites, i_suites_len, add_suite___list_node_pri_get_chklist);
    add_suites(fun_suites, i_suites_len, add_suite___list_node_pri_show);
    add_suites(fun_suites, i_suites_len, add_suite___list_node_priority_find);
    add_suites(fun_suites, i_suites_len, add_suite_frproto_cfg_load);
    add_suites(fun_suites, i_suites_len, add_suite_frproto_get_chklist);


    //t_frstat_module
    add_suites(fun_suites, i_suites_len, add_suite___stat_module_count_avg);
    add_suites(fun_suites, i_suites_len, add_suite___frhash_make_key);
    add_suites(fun_suites, i_suites_len, add_suite___frmodule_bps);
    add_suites(fun_suites, i_suites_len, add_suite___frmodule_show);
    add_suites(fun_suites, i_suites_len, add_suite_frstat_module_add);
    add_suites(fun_suites, i_suites_len, add_suite_frstat_module_del);
    add_suites(fun_suites, i_suites_len, add_suite_frstat_module_get_info);
    add_suites(fun_suites, i_suites_len, add_suite_frstat_module_init);
    add_suites(fun_suites, i_suites_len, add_suite_frstat_module_output);

    //t_frstat_thread
    add_suites(fun_suites, i_suites_len, add_suite_frstat_thread_init);
    add_suites(fun_suites, i_suites_len, add_suite___stat_thread_count_avg);
    add_suites(fun_suites, i_suites_len, add_suite___frstat_thread_count);
    add_suites(fun_suites, i_suites_len, add_suite___frstat_thread_output);
    add_suites(fun_suites, i_suites_len, add_suite_frstat_thread_add);
    add_suites(fun_suites, i_suites_len, add_suite_frstat_thread_del);
    add_suites(fun_suites, i_suites_len, add_suite_frstat_thread_output);

    //t_frssl_config
    add_suites(fun_suites, i_suites_len, add_suite___frssl_analyse_xml);
    add_suites(fun_suites, i_suites_len, add_suite___frssl_config_add);
    add_suites(fun_suites, i_suites_len, add_suite___frssl_config_del);
    add_suites(fun_suites, i_suites_len, add_suite___frssl_xml_add);

    for (;i_loop < i_suites_len; i_loop++)
    {
        if (fun_suites[i_loop] != NULL && fun_suites[i_loop]() != 0)
        {
            CU_cleanup_registry();
            return CU_get_error();
        }
    }

    apmtest_cunit_unregistry();
    fr_slab_destroy();

    return 0;
}
